package com.my.meitianbackup.utils;

import java.util.ArrayList;
import java.util.List;

public class ExtractMessage {
/*	public static void main(String[] args) {

		String msg = "PerformanceManager{第1个大括号}Product{第2个大括号{大括号大包含大括号}}<{第3个大括号}79~";
		List<String> list = extractMessage(msg);
		for (int i = 0; i < list.size(); i++) {
			System.out.println(i + "-->" + list.get(i));
		}
	}*/

	/**
	 * 提取大括号大内容，忽略大括号大的大括号
	 * 
	 * @param msg
	 * @return
	 */
	public static List<String> extractMessage(String msg) {

		List<String> list = new ArrayList<String>();
		int start = 0;
		int startFlag = 0;
		int endFlag = 0;
		for (int i = 0; i < msg.length(); i++) {
			if (msg.charAt(i) == '{') {
				startFlag++;
				if (startFlag == endFlag + 1) {
					start = i;
				}
			} else if (msg.charAt(i) == '}') {
				endFlag++;
				if (endFlag == startFlag) {
					list.add(msg.substring(start + 1, i));
				}
			}
		}
		return list;
	}
}
